<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha256-CTSx/A06dm1B063156EVh15m6Y67pAjZZaQc89LLSrU=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.css" integrity="sha256-vQkngPS8jiHHH0I6ABTZroZk8NPZ7b+MUReOFE9UsXQ=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"rjyblog.gitee.io","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.18.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":null},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文以时序图的形式来展示activity的启动过程，相比于贴源码会更加直观。本文的讲解的流程是基于MainActivity使用standard模式启动SecondActivity，且两个Activity都在同一个应用中，最后的部分也会讲解一下进程的启动。 第一阶段：执行startActivity  zenuml group App {     &lt;&lt;App&gt;&gt; act a">
<meta property="og:type" content="article">
<meta property="og:title" content="Activity启动流程 (Android13)">
<meta property="og:url" content="https://rjyblog.gitee.io/posts/93b40782.html">
<meta property="og:site_name" content="任建勇的博客">
<meta property="og:description" content="本文以时序图的形式来展示activity的启动过程，相比于贴源码会更加直观。本文的讲解的流程是基于MainActivity使用standard模式启动SecondActivity，且两个Activity都在同一个应用中，最后的部分也会讲解一下进程的启动。 第一阶段：执行startActivity  zenuml group App {     &lt;&lt;App&gt;&gt; act a">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://rjyblog.gitee.io/images/Android/Activity_Transaction%E7%B1%BB%E5%9B%BE.drawio.svg">
<meta property="og:image" content="https://rjyblog.gitee.io/images/Android/DecorView%E7%A4%BA%E4%BE%8B.png">
<meta property="article:published_time" content="2023-10-07T03:11:56.000Z">
<meta property="article:modified_time" content="2024-01-05T11:09:25.146Z">
<meta property="article:author" content="Jason">
<meta property="article:tag" content="Android">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://rjyblog.gitee.io/images/Android/Activity_Transaction%E7%B1%BB%E5%9B%BE.drawio.svg">


<link rel="canonical" href="https://rjyblog.gitee.io/posts/93b40782.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://rjyblog.gitee.io/posts/93b40782.html","path":"posts/93b40782.html","title":"Activity启动流程 (Android13)"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Activity启动流程 (Android13) | 任建勇的博客</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">任建勇的博客</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AC%AC%E4%B8%80%E9%98%B6%E6%AE%B5%EF%BC%9A%E6%89%A7%E8%A1%8CstartActivity"><span class="nav-text">第一阶段：执行startActivity</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AC%AC%E4%BA%8C%E9%98%B6%E6%AE%B5%EF%BC%9Apause%E5%BD%93%E5%89%8Dactivity"><span class="nav-text">第二阶段：pause当前activity</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AC%AC%E4%B8%89%E9%98%B6%E6%AE%B5%EF%BC%9A%E5%90%AF%E5%8A%A8%E6%96%B0Activity"><span class="nav-text">第三阶段：启动新Activity</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AC%AC%E5%9B%9B%E9%98%B6%E6%AE%B5%EF%BC%9AView%E6%B7%BB%E5%8A%A0%E5%88%B0Window"><span class="nav-text">第四阶段：View添加到Window</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%AF%E5%8A%A8%E6%96%B0APP%E8%BF%9B%E7%A8%8B"><span class="nav-text">启动新APP进程</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Jason"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">Jason</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">66</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">13</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/93b40782.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Activity启动流程 (Android13) | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Activity启动流程 (Android13)
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-10-07 11:11:56" itemprop="dateCreated datePublished" datetime="2023-10-07T11:11:56+08:00">2023-10-07</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-01-05 19:09:25" itemprop="dateModified" datetime="2024-01-05T19:09:25+08:00">2024-01-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><!-- toc -->

<p>本文以时序图的形式来展示activity的启动过程，相比于贴源码会更加直观。本文的讲解的流程是基于<code>MainActivity</code>使用standard模式启动<code>SecondActivity</code>，且两个Activity都在同一个应用中，最后的部分也会讲解一下进程的启动。</p>
<h2 id="第一阶段：执行startActivity"><a href="#第一阶段：执行startActivity" class="headerlink" title="第一阶段：执行startActivity"></a>第一阶段：执行startActivity</h2><pre class="mermaid">

zenuml
group App {
    &lt;&lt;App&gt;&gt; act as Activity
    &lt;&lt;App&gt;&gt; ins as Instrumentation
}
group AMS {
    &lt;&lt;AMS&gt;&gt; atms as ActivityTaskManagerService #F0F8FF
    ActivityStarter #F0F8FF
}
act.startActivity {
    act.startActivityForResult {
        ins.execStartActivity {
            atms.startActivity {
                atms.startActivityAsUser {
                    &#x2F;&#x2F;没有缓存则创建
                    new ActivityStarter()
                    ActivityStarter.&quot;① execute&quot;
                }
            }
        }
    }
}
</pre>

<pre class="mermaid">

zenuml
&lt;&lt;AMS&gt;&gt; ActivityStarter #F0F8FF
ActivityStarter.&quot;① execute&quot; {
    executeRequest {
        new ActivityRecord()
        startActivityUnchecked {
            startActivityInner {
                Task.addChild
                Task.startActivityLocked
                RootWindowContainer.resumeFocusedTasksTopActivities {
                    Task.resumeTopActivityUncheckedLocked {
                        resumeTopActivityInnerLocked {
                            TaskFragment.resumeTopActivity {
                                &#x2F;&#x2F;pause当前activity
                                &quot;② startPausing()&quot;
                                if (! isProcessRunning) {
                                    ActivityTaskManagerService.startProcessAsync
                                }
                            }
                        }
                    }
                }
            }
            handleStartResult
            postStartActivityProcessing
        }
    }
}
</pre>

<h2 id="第二阶段：pause当前activity"><a href="#第二阶段：pause当前activity" class="headerlink" title="第二阶段：pause当前activity"></a>第二阶段：pause当前activity</h2><p>启动<code>SecondActivity</code>之前会先执行<code>MainActivity</code>的<strong>pause</strong>操作：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="955px" preserveAspectRatio="none" style="width:1004px;height:955px;background:#FFFFFF;" version="1.1" viewBox="0 0 1004 955" width="1004px" zoomAndPan="magnify"><defs/><g><rect fill="#F0F8FF" height="943.9141" style="stroke:#181818;stroke-width:0.5;" width="470" x="75.5" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="32" x="292" y="18.0669">AMS</text><rect fill="#F0F0F0" height="943.9141" style="stroke:#181818;stroke-width:0.5;" width="450.5" x="547.5" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="30" x="755.25" y="18.0669">APP</text><rect fill="#FFFFFF" height="274.0625" style="stroke:#181818;stroke-width:1.0;" width="10" x="133" y="87.5625"/><rect fill="#FFBBBB" height="236.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="138" y="124.6953"/><rect fill="#FFFFFF" height="137.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="143" y="224.0938"/><rect fill="#FFFFFF" height="74.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="335" y="331.625"/><rect fill="#FFFFFF" height="68.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="476" y="838.4844"/><rect fill="#FFFFFF" height="85.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="443.0234"/><rect fill="#FFFFFF" height="34.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="572.4219"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="692.9531"/><rect fill="#FFFFFF" height="261.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="787.5" y="606.5547"/><rect fill="#FFFFFF" height="63.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="658.8203"/><rect fill="#FFFFFF" height="94.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="774.3516"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="137.5" x2="137.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="339.5" x2="339.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="480.5" x2="480.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="611.5" x2="611.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="792.5" x2="792.5" y1="56.4297" y2="915.6172"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="942" x2="942" y1="56.4297" y2="915.6172"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="117" x="79.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="103" x="86.5" y="45.1279">TaskFragment</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="117" x="79.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="103" x="86.5" y="934.6123">TaskFragment</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="141" x="269.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="276.5" y="45.1279">ClientTransaction</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="141" x="269.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="276.5" y="934.6123">ClientTransaction</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="121" x="420.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="107" x="427.5" y="45.1279">ActivityRecord</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="121" x="420.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="107" x="427.5" y="934.6123">ActivityRecord</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="551.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="558.5" y="45.1279">ActivityThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="551.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="558.5" y="934.6123">ActivityThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="711.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="148" x="718.5" y="45.1279">TransactionExecutor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="711.5" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="148" x="718.5" y="934.6123">TransactionExecutor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="103" x="891" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="89" x="898" y="45.1279">MainActivity</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="103" x="891" y="914.6172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="89" x="898" y="934.6123">MainActivity</text><rect fill="#FFFFFF" height="274.0625" style="stroke:#181818;stroke-width:1.0;" width="10" x="133" y="87.5625"/><rect fill="#FFBBBB" height="236.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="138" y="124.6953"/><rect fill="#FFFFFF" height="137.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="143" y="224.0938"/><rect fill="#FFFFFF" height="74.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="335" y="331.625"/><rect fill="#FFFFFF" height="68.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="476" y="838.4844"/><rect fill="#FFFFFF" height="85.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="443.0234"/><rect fill="#FFFFFF" height="34.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="572.4219"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="606.5" y="692.9531"/><rect fill="#FFFFFF" height="261.9297" style="stroke:#181818;stroke-width:1.0;" width="10" x="787.5" y="606.5547"/><rect fill="#FFFFFF" height="63.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="658.8203"/><rect fill="#FFFFFF" height="94.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="792.5" y="774.3516"/><ellipse cx="7.5" cy="86.8125" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="121,83.5625,131,87.5625,121,91.5625,125,87.5625" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="127" y1="87.5625" y2="87.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="106" x="10" y="82.4966">&#9313; startPausing()</text><line style="stroke:#181818;stroke-width:1.0;" x1="143" x2="190" y1="111.6953" y2="111.6953"/><line style="stroke:#181818;stroke-width:1.0;" x1="190" x2="190" y1="111.6953" y2="124.6953"/><line style="stroke:#181818;stroke-width:1.0;" x1="149" x2="190" y1="124.6953" y2="124.6953"/><polygon fill="#181818" points="159,120.6953,149,124.6953,159,128.6953,155,124.6953" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="144" x="155" y="106.6294">schedulePauseActivity</text><line style="stroke:#181818;stroke-width:1.0;" x1="148" x2="190" y1="158.8281" y2="158.8281"/><line style="stroke:#181818;stroke-width:1.0;" x1="190" x2="190" y1="158.8281" y2="171.8281"/><line style="stroke:#181818;stroke-width:1.0;" x1="149" x2="190" y1="171.8281" y2="171.8281"/><polygon fill="#181818" points="159,167.8281,149,171.8281,159,175.8281,155,171.8281" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="170" x="155" y="153.7622">PauseActivityItem.obtain()</text><line style="stroke:#181818;stroke-width:1.0;" x1="148" x2="195" y1="211.0938" y2="211.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="195" x2="195" y1="211.0938" y2="224.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="154" x2="195" y1="224.0938" y2="224.0938"/><polygon fill="#181818" points="164,220.0938,154,224.0938,164,228.0938,160,224.0938" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="151" x="160" y="190.895">ClientLifecycleManager.</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="132" x="164" y="206.0278">scheduleTransaction</text><polygon fill="#181818" points="328,254.2266,338,258.2266,328,262.2266,332,258.2266" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="153" x2="334" y1="258.2266" y2="258.2266"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="40" x="283" y="253.1606">obtain</text><polygon fill="#181818" points="328,298.4922,338,302.4922,328,306.4922,332,302.4922" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="153" x2="334" y1="302.4922" y2="302.4922"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="163" x="160" y="282.2935">setLifecycleStateRequest</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="126" x="160" y="297.4263">(PauseActivityItem)</text><polygon fill="#181818" points="323,327.625,333,331.625,323,335.625,327,331.625" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="153" x2="329" y1="331.625" y2="331.625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="67" x="251" y="326.5591">schedule()</text><polygon fill="#181818" points="599.5,401.8906,609.5,405.8906,599.5,409.8906,603.5,405.8906" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="340" x2="605.5" y1="405.8906" y2="405.8906"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="136" x="429.5" y="385.6919">[ApplicationThread]&#8594;</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="165" x="429.5" y="400.8247">scheduleTransaction(this)</text><line style="stroke:#181818;stroke-width:1.0;" x1="616.5" x2="658.5" y1="435.0234" y2="435.0234"/><line style="stroke:#181818;stroke-width:1.0;" x1="658.5" x2="658.5" y1="435.0234" y2="448.0234"/><line style="stroke:#181818;stroke-width:1.0;" x1="617.5" x2="658.5" y1="448.0234" y2="448.0234"/><polygon fill="#181818" points="627.5,444.0234,617.5,448.0234,627.5,452.0234,623.5,448.0234" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="132" x="623.5" y="429.9575">scheduleTransaction</text><line style="stroke:#181818;stroke-width:1.0;" x1="616.5" x2="658.5" y1="527.2891" y2="527.2891"/><line style="stroke:#181818;stroke-width:1.0;" x1="658.5" x2="658.5" y1="527.2891" y2="540.2891"/><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="658.5" y1="540.2891" y2="540.2891"/><polygon fill="#181818" points="621.5,536.2891,611.5,540.2891,621.5,544.2891,617.5,540.2891" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="92" x="623.5" y="507.0903">sendMessage:</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="157" x="623.5" y="522.2231">EXECUTE_TRANSACTION</text><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="658.5" y1="559.4219" y2="559.4219"/><line style="stroke:#181818;stroke-width:1.0;" x1="658.5" x2="658.5" y1="559.4219" y2="572.4219"/><line style="stroke:#181818;stroke-width:1.0;" x1="617.5" x2="658.5" y1="572.4219" y2="572.4219"/><polygon fill="#181818" points="627.5,568.4219,617.5,572.4219,627.5,576.4219,623.5,572.4219" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="109" x="623.5" y="554.356">handleMessage()</text><polygon fill="#181818" points="775.5,602.5547,785.5,606.5547,775.5,610.5547,779.5,606.5547" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="781.5" y1="606.5547" y2="606.5547"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="134" x="636.5" y="601.4888">execute(transaction)</text><line style="stroke:#181818;stroke-width:1.0;" x1="797.5" x2="844.5" y1="645.8203" y2="645.8203"/><line style="stroke:#181818;stroke-width:1.0;" x1="844.5" x2="844.5" y1="645.8203" y2="658.8203"/><line style="stroke:#181818;stroke-width:1.0;" x1="803.5" x2="844.5" y1="658.8203" y2="658.8203"/><polygon fill="#181818" points="813.5,654.8203,803.5,658.8203,813.5,662.8203,809.5,658.8203" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="126" x="809.5" y="625.6216">[PauseActivityItem]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="73" x="809.5" y="640.7544">&#8594;execute()</text><polygon fill="#181818" points="627.5,688.9531,617.5,692.9531,627.5,696.9531,623.5,692.9531" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="621.5" x2="791.5" y1="692.9531" y2="692.9531"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="130" x="633.5" y="687.8872">handlePauseActivity</text><polygon fill="#181818" points="930.5,718.0859,940.5,722.0859,930.5,726.0859,934.5,722.0859" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="611.5" x2="936.5" y1="722.0859" y2="722.0859"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65" x="860.5" y="717.02">onPause()</text><line style="stroke:#181818;stroke-width:1.0;" x1="802.5" x2="844.5" y1="766.3516" y2="766.3516"/><line style="stroke:#181818;stroke-width:1.0;" x1="844.5" x2="844.5" y1="766.3516" y2="779.3516"/><line style="stroke:#181818;stroke-width:1.0;" x1="803.5" x2="844.5" y1="779.3516" y2="779.3516"/><polygon fill="#181818" points="813.5,775.3516,803.5,779.3516,813.5,783.3516,809.5,779.3516" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="126" x="809.5" y="746.1528">[PauseActivityItem]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="91" x="809.5" y="761.2856">&#8594;postExecute</text><polygon fill="#181818" points="497,834.4844,487,838.4844,497,842.4844,493,838.4844" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="491" x2="791.5" y1="838.4844" y2="838.4844"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="94" x="503" y="833.4185">activityPaused</text><polygon fill="#181818" points="149,893.6172,139,897.6172,149,901.6172,145,897.6172" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="143" x2="475" y1="897.6172" y2="897.6172"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="115" x="155" y="892.5513">&#9314; completePause</text><!--SRC=[hLJDJkCm4BxdAInnIOMAEA8UaBAbaP0eL6rMGceG6foXjKZjOBi8Ne3xyWRBe_4aZ1EovA-RhhJ99R5dllc-ppCs3q9ce67333vkKNASeZ6mmY0LAyaqFg4sU2OqSYkKzExKCmkc2tOG7eSdOUWjrV2KHM0UGWsh3KhB3Wz7xEFNRsOiQ3k3hH5ovG-yMampPyGCNsEoJT4bO42rdeHzyS1zWCLwz44O_g2d3x86TMvnSwJkB0ZPHyO96AU2FY_4FV8Ndk8K95cYZsBvXsYaGHeeJ6d25TcL269JrDuhrE1tvOKb-NDtDCR6qczf6ko1w0ILj4byWfss_lCwjOqLN6H0TKjAS-HA9nxAX56dU4Mxp6Pvkz3hjSaHup8vMck4X0s78xOCiYmL75n8iNppyVeMomxtVRiMPk0rGLgmLHUgXxTBNY-Wusb8wTV0Z5Wi9zUJySzeSXlDWyj5C8xEhoxt8xO6cQJbwFbTQYgK9y_8jrPfOk1oCVz5ttv7K5TqXNUZE8nbgx5kOacEbzWx0NTggGzoMy-Kfg5SpQrKCazfD6Yxwl-IbYbZYq2iLgmp_SjEZo759EGCu6if9vBqoUlPhezMvIPk56xSQkvEVcTSRR8KRN4u9TGd]--></g></svg>

<p>在Android 9之前的版本，<code>ActivityThread</code>中通过<code>LAUNCH_ACTIVITY</code>消息来启动activity，源码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//android\app\ActivityThread.java</span></span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">handleMessage</span><span class="params">(Message msg)</span> &#123;</span><br><span class="line">            <span class="keyword">if</span> (DEBUG_MESSAGES) Slog.v(TAG, <span class="string">&quot;&gt;&gt;&gt; handling: &quot;</span> + codeToString(msg.what));</span><br><span class="line">            <span class="keyword">switch</span> (msg.what) &#123;</span><br><span class="line">                <span class="keyword">case</span> LAUNCH_ACTIVITY: &#123;</span><br><span class="line">                    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, <span class="string">&quot;activityStart&quot;</span>);</span><br><span class="line">                    <span class="keyword">final</span> <span class="type">ActivityClientRecord</span> <span class="variable">r</span> <span class="operator">=</span> (ActivityClientRecord) msg.obj;</span><br><span class="line"></span><br><span class="line">                    r.packageInfo = getPackageInfoNoCheck(</span><br><span class="line">                            r.activityInfo.applicationInfo, r.compatInfo);</span><br><span class="line">                    handleLaunchActivity(r, <span class="literal">null</span>, <span class="string">&quot;LAUNCH_ACTIVITY&quot;</span>);</span><br><span class="line">                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);</span><br><span class="line">                &#125; <span class="keyword">break</span>;</span><br></pre></td></tr></table></figure>

<p>但从Andorid 9开始，<code>ActivityThread</code>去掉了<code>LAUNCH_ACTIVITY</code> <code>PAUSE_ACTIVITY</code> <code>RESUME_ACTIVITY</code>等消息，而是改成了EXECUTE_TRANSACTION，通过ClientTransaction这套机制来执行activity生命周期流程，相关源码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">handleMessage</span><span class="params">(Message msg)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (DEBUG_MESSAGES) Slog.v(TAG, <span class="string">&quot;&gt;&gt;&gt; handling: &quot;</span> + codeToString(msg.what));</span><br><span class="line">    <span class="keyword">switch</span> (msg.what) &#123;</span><br><span class="line">        ......</span><br><span class="line">        <span class="keyword">case</span> EXECUTE_TRANSACTION:</span><br><span class="line">            <span class="keyword">final</span> <span class="type">ClientTransaction</span> <span class="variable">transaction</span> <span class="operator">=</span> (ClientTransaction) msg.obj;</span><br><span class="line">            mTransactionExecutor.execute(transaction);</span><br><span class="line">            <span class="keyword">if</span> (isSystem()) &#123;</span><br><span class="line">                <span class="comment">// Client transactions inside system process are recycled on the client side</span></span><br><span class="line">                <span class="comment">// instead of ClientLifecycleManager to avoid being cleared before this</span></span><br><span class="line">                <span class="comment">// message is handled.</span></span><br><span class="line">                transaction.recycle();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// TODO(lifecycler): Recycle locally scheduled transactions.</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br></pre></td></tr></table></figure>

<p>下面是<code>ClientTransaction</code>类图：</p>
<p><img src="/images/Android/Activity_Transaction%E7%B1%BB%E5%9B%BE.drawio.svg" alt="Activity Transaction"></p>
<h2 id="第三阶段：启动新Activity"><a href="#第三阶段：启动新Activity" class="headerlink" title="第三阶段：启动新Activity"></a>第三阶段：启动新Activity</h2><p>下面继续Activity启动流程：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="334px" preserveAspectRatio="none" style="width:983px;height:334px;background:#FFFFFF;" version="1.1" viewBox="0 0 983 334" width="983px" zoomAndPan="magnify"><defs/><g><rect fill="#F0F8FF" height="322.5234" style="stroke:#181818;stroke-width:0.5;" width="893" x="84.5" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="32" x="512.5" y="18.0669">AMS</text><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="142" y="87.5625"/><rect fill="#FFFFFF" height="59.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="142" y="217.0938"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="392" y="116.6953"/><rect fill="#FFFFFF" height="101.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="657" y="145.8281"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="662" y="182.9609"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="146.5" x2="146.5" y1="56.4297" y2="294.2266"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="397" x2="397" y1="56.4297" y2="294.2266"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="661.5" x2="661.5" y1="56.4297" y2="294.2266"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="883.5" x2="883.5" y1="56.4297" y2="294.2266"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="117" x="88.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="103" x="95.5" y="45.1279">TaskFragment</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="117" x="88.5" y="293.2266"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="103" x="95.5" y="313.2217">TaskFragment</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="176" x="309" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="162" x="316" y="45.1279">RootWindowContainer</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="176" x="309" y="293.2266"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="162" x="316" y="313.2217">RootWindowContainer</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="47" x="638.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="33" x="645.5" y="45.1279">Task</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="47" x="638.5" y="293.2266"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="33" x="645.5" y="313.2217">Task</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="179" x="794.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="165" x="801.5" y="45.1279">ActivityTaskSupervisor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="179" x="794.5" y="293.2266"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="165" x="801.5" y="313.2217">ActivityTaskSupervisor</text><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="142" y="87.5625"/><rect fill="#FFFFFF" height="59.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="142" y="217.0938"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="392" y="116.6953"/><rect fill="#FFFFFF" height="101.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="657" y="145.8281"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="662" y="182.9609"/><ellipse cx="7.5" cy="86.8125" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="130,83.5625,140,87.5625,130,91.5625,134,87.5625" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="136" y1="87.5625" y2="87.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="115" x="15" y="82.4966">&#9314; completePause</text><polygon fill="#181818" points="380,112.6953,390,116.6953,380,120.6953,384,116.6953" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="147" x2="386" y1="116.6953" y2="116.6953"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="221" x="154" y="111.6294">resumeFocusedTasksTopActivities</text><polygon fill="#181818" points="645,141.8281,655,145.8281,645,149.8281,649,145.8281" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="397" x2="651" y1="145.8281" y2="145.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="236" x="404" y="140.7622">resumeTopActivityUncheckedLocked</text><line style="stroke:#181818;stroke-width:1.0;" x1="667" x2="714" y1="169.9609" y2="169.9609"/><line style="stroke:#181818;stroke-width:1.0;" x1="714" x2="714" y1="169.9609" y2="182.9609"/><line style="stroke:#181818;stroke-width:1.0;" x1="673" x2="714" y1="182.9609" y2="182.9609"/><polygon fill="#181818" points="683,178.9609,673,182.9609,683,186.9609,679,182.9609" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="198" x="679" y="164.895">resumeTopActivityInnerLocked</text><polygon fill="#181818" points="163,213.0938,153,217.0938,163,221.0938,159,217.0938" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="157" x2="661" y1="217.0938" y2="217.0938"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="121" x="169" y="212.0278">resumeTopActivity</text><polygon fill="#181818" points="872,272.2266,882,276.2266,872,280.2266,876,276.2266" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="147" x2="878" y1="276.2266" y2="276.2266"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="143" x="154" y="271.1606">&#9315; startSpecificActivity</text><!--SRC=[RT1B2i8m40RWVKunu58ABiM58490K12hk70Lar63DbEIgOzZU0MzcIUnyKcrcv24_vj9Pab7w8rIQCYMR4if5fHqOQh2Ldgrpj0nD9iTk9qle2dBTyWuLaL0KOcKP4B4S-iC7VhaM5c77f8aMe-Xo52IBfc9B4mfxscsUyiMWwYLppTKAdpLQURq1lKMpP3YAfxPbwaL0rUMhKbNVlcdX44LjuhnaVux_qxX3UDzMkJezpPG74GSuHK2AyzfZjgkhFuqGMTWISSx]--></g></svg>

<p>执行<code>SecondAcitivity</code>的启动流程：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="677px" preserveAspectRatio="none" style="width:1018px;height:677px;background:#FFFFFF;" version="1.1" viewBox="0 0 1018 677" width="1018px" zoomAndPan="magnify"><defs/><g><rect fill="#F0F8FF" height="665.9844" style="stroke:#181818;stroke-width:0.5;" width="513" x="81.5" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="32" x="319.5" y="18.0669">AMS</text><rect fill="#F0F0F0" height="665.9844" style="stroke:#181818;stroke-width:0.5;" width="302.5" x="603.5" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="30" x="737.25" y="18.0669">APP</text><rect fill="#FFFFFF" height="541.125" style="stroke:#181818;stroke-width:1.0;" width="10" x="170" y="87.5625"/><rect fill="#FFFFFF" height="322.1953" style="stroke:#181818;stroke-width:1.0;" width="10" x="175" y="124.6953"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="180" y="382.7578"/><rect fill="#FFFFFF" height="59.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="515" y="416.8906"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="676" y="476.0234"/><rect fill="#FFFFFF" height="50.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="837" y="505.1563"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="174.5" x2="174.5" y1="56.4297" y2="637.6875"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="378.5" x2="378.5" y1="56.4297" y2="637.6875"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="519.5" x2="519.5" y1="56.4297" y2="637.6875"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="680.5" x2="680.5" y1="56.4297" y2="637.6875"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="842" x2="842" y1="56.4297" y2="637.6875"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="179" x="85.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="165" x="92.5" y="45.1279">ActivityTaskSupervisor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="179" x="85.5" y="636.6875"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="165" x="92.5" y="656.6826">ActivityTaskSupervisor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="121" x="318.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="107" x="325.5" y="45.1279">ActivityRecord</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="121" x="318.5" y="636.6875"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="107" x="325.5" y="656.6826">ActivityRecord</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="141" x="449.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="456.5" y="45.1279">ClientTransaction</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="141" x="449.5" y="636.6875"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="456.5" y="656.6826">ClientTransaction</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="147" x="607.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="133" x="614.5" y="45.1279">ApplicationThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="147" x="607.5" y="636.6875"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="133" x="614.5" y="656.6826">ApplicationThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="782" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="789" y="45.1279">ActivityThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="782" y="636.6875"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="789" y="656.6826">ActivityThread</text><rect fill="#FFFFFF" height="541.125" style="stroke:#181818;stroke-width:1.0;" width="10" x="170" y="87.5625"/><rect fill="#FFFFFF" height="322.1953" style="stroke:#181818;stroke-width:1.0;" width="10" x="175" y="124.6953"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="180" y="382.7578"/><rect fill="#FFFFFF" height="59.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="515" y="416.8906"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="676" y="476.0234"/><rect fill="#FFFFFF" height="50.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="837" y="505.1563"/><ellipse cx="7.5" cy="86.8125" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="158,83.5625,168,87.5625,158,91.5625,162,87.5625" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="164" y1="87.5625" y2="87.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="143" x="15" y="82.4966">&#9315; startSpecificActivity</text><line style="stroke:#181818;stroke-width:1.0;" x1="180" x2="227" y1="111.6953" y2="111.6953"/><line style="stroke:#181818;stroke-width:1.0;" x1="227" x2="227" y1="111.6953" y2="124.6953"/><line style="stroke:#181818;stroke-width:1.0;" x1="186" x2="227" y1="124.6953" y2="124.6953"/><polygon fill="#181818" points="196,120.6953,186,124.6953,196,128.6953,192,124.6953" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="148" x="192" y="106.6294">realStartActivityLocked</text><polygon fill="#181818" points="367,154.8281,377,158.8281,367,162.8281,371,158.8281" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="185" x2="373" y1="158.8281" y2="158.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="70" x="192" y="153.7622">setProcess</text><polygon fill="#181818" points="508,183.9609,518,187.9609,508,191.9609,512,187.9609" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="185" x2="514" y1="187.9609" y2="187.9609"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="40" x="192" y="182.895">obtain</text><line style="stroke:#181818;stroke-width:1.0;" x1="185" x2="227" y1="217.0938" y2="217.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="227" x2="227" y1="217.0938" y2="230.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="186" x2="227" y1="230.0938" y2="230.0938"/><polygon fill="#181818" points="196,226.0938,186,230.0938,196,234.0938,192,230.0938" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="167" x="192" y="212.0278">LaunchActivityItem.obtain</text><polygon fill="#181818" points="508,255.2266,518,259.2266,508,263.2266,512,259.2266" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="185" x2="514" y1="259.2266" y2="259.2266"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="210" x="192" y="254.1606">addCallback(LaunchActivityItem)</text><line style="stroke:#181818;stroke-width:1.0;" x1="185" x2="227" y1="288.3594" y2="288.3594"/><line style="stroke:#181818;stroke-width:1.0;" x1="227" x2="227" y1="288.3594" y2="301.3594"/><line style="stroke:#181818;stroke-width:1.0;" x1="186" x2="227" y1="301.3594" y2="301.3594"/><polygon fill="#181818" points="196,297.3594,186,301.3594,196,305.3594,192,301.3594" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="174" x="192" y="283.2935">ResumeActivityItem.obtain</text><polygon fill="#181818" points="508,326.4922,518,330.4922,508,334.4922,512,330.4922" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="185" x2="514" y1="330.4922" y2="330.4922"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="303" x="192" y="325.4263">setLifecycleStateRequest(ResumeActivityItem)</text><line style="stroke:#181818;stroke-width:1.0;" x1="185" x2="232" y1="369.7578" y2="369.7578"/><line style="stroke:#181818;stroke-width:1.0;" x1="232" x2="232" y1="369.7578" y2="382.7578"/><line style="stroke:#181818;stroke-width:1.0;" x1="191" x2="232" y1="382.7578" y2="382.7578"/><polygon fill="#181818" points="201,378.7578,191,382.7578,201,386.7578,197,382.7578" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="157" x="197" y="349.5591">[ClientLifecycleManager]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="143" x="197" y="364.6919">&#8594;scheduleTransaction</text><polygon fill="#181818" points="503,412.8906,513,416.8906,503,420.8906,507,416.8906" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="190" x2="509" y1="416.8906" y2="416.8906"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65" x="197" y="411.8247">&#160;&#160;schedule</text><polygon fill="#181818" points="664,472.0234,674,476.0234,664,480.0234,668,476.0234" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="520" x2="670" y1="476.0234" y2="476.0234"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="132" x="527" y="470.9575">scheduleTransaction</text><polygon fill="#181818" points="825,501.1563,835,505.1563,825,509.1563,829,505.1563" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="681" x2="831" y1="505.1563" y2="505.1563"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="132" x="688" y="500.0903">scheduleTransaction</text><line style="stroke:#181818;stroke-width:1.0;" x1="847" x2="889" y1="554.4219" y2="554.4219"/><line style="stroke:#181818;stroke-width:1.0;" x1="889" x2="889" y1="554.4219" y2="567.4219"/><line style="stroke:#181818;stroke-width:1.0;" x1="842" x2="889" y1="567.4219" y2="567.4219"/><polygon fill="#181818" points="852,563.4219,842,567.4219,852,571.4219,848,567.4219" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="108" x="854" y="534.2231">&#9316; sendMessage:</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="157" x="854" y="549.356">EXECUTE_TRANSACTION</text><line style="stroke:#181818;stroke-width:1.0;" x1="180" x2="222" y1="606.6875" y2="606.6875"/><line style="stroke:#181818;stroke-width:1.0;" x1="222" x2="222" y1="606.6875" y2="619.6875"/><line style="stroke:#181818;stroke-width:1.0;" x1="181" x2="222" y1="619.6875" y2="619.6875"/><polygon fill="#181818" points="191,615.6875,181,619.6875,191,623.6875,187,619.6875" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="180" x="187" y="586.4888">ActivityTaskManagerService</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="123" x="187" y="601.6216">.startProcessAsync</text><!--SRC=[fLJjQi8m5FtVfmW8Gn75_HcZWq4f5WHrqdOmq37Iv3g3DUcQLFG5zdzxXUt9V98bQZUt-ZqAXJRdd7lkFRsDn0mvdG2Ll8PtxNbMNzHkaKCKcp8r3x4S1ra2wPH9aQ9grKQBjmya5KvLa01XGqPohBM3j5yk1Hm7HYx7j0KP0pr2p0SYKefi947rKa50oZqiDsR0LPXYBh462Qw98bAOyTDzswYDCqv6-N5BmQH-K6oR0qofY-CumcHSBcfMph7cWymcy7zhUgfjDWGo9p7eW1Juy9A1LELYWSfvqVTNPR-hT337pv0-3lZYzLsI4T0iXWrJ9pLW2boKBgyQDwjxhcTP50nagZlQOUu8172A8Z6phCXiJw-tt1vzMKKZPWP94ZE2pMCuqXyyHRMQyRUrno9sOuW7sN-0MwXcWpzrkfnszCReWTi3tdneklTXyodqdMxWk67hhllJugdPsh_UhqCDp2610Qyl_nthVNNad9Cl]--></g></svg>

<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="1166px" preserveAspectRatio="none" style="width:982px;height:1166px;background:#FFFFFF;" version="1.1" viewBox="0 0 982 1166" width="982px" zoomAndPan="magnify"><defs/><g><rect fill="#F0F0F0" height="1154.0391" style="stroke:#181818;stroke-width:0.5;" width="851.5" x="125" y="6"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacing" textLength="30" x="533.25" y="18.0669">APP</text><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="102.6953"/><rect fill="#FFFFFF" height="370.6563" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="218.2266"/><rect fill="#FFFFFF" height="303.5234" style="stroke:#181818;stroke-width:1.0;" width="10" x="189" y="285.3594"/><rect fill="#FFFFFF" height="76.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="194" y="327.4922"/><rect fill="#FFFFFF" height="19" style="stroke:#181818;stroke-width:1.0;" width="10" x="199" y="384.7578"/><rect fill="#FFFFFF" height="59.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="744.4141"/><rect fill="#FFFFFF" height="168.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="948.2109"/><rect fill="#FFFFFF" height="34.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="189" y="1015.3438"/><rect fill="#FFFFFF" height="846.3828" style="stroke:#181818;stroke-width:1.0;" width="10" x="404" y="131.8281"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="409" y="184.0938"/><rect fill="#FFFFFF" height="352.1953" style="stroke:#181818;stroke-width:1.0;" width="10" x="409" y="626.0156"/><rect fill="#FFFFFF" height="106.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="414" y="668.1484"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="419" y="710.2813"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="414" y="914.0781"/><rect fill="#FFFFFF" height="14" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="460.1875"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="559.75"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="832.6797"/><rect fill="#FFFFFF" height="38.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="1078.6094"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="906" y="803.5469"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="906" y="1049.4766"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="189" x2="189" y1="56.4297" y2="1125.7422"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="409" x2="409" y1="56.4297" y2="1125.7422"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="613.5" x2="613.5" y1="428.4063" y2="1125.7422"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="741.5" x2="741.5" y1="56.4297" y2="1125.7422"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="910.5" x2="910.5" y1="498.8359" y2="1125.7422"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="129" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="136" y="45.1279">ActivityThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="120" x="129" y="1124.7422"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="136" y="1144.7373">ActivityThread</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="328" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="148" x="335" y="45.1279">TransactionExecutor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="328" y="1124.7422"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="148" x="335" y="1144.7373">TransactionExecutor</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="105" x="561.5" y="1124.7422"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="91" x="568.5" y="1144.7373">ContextImpl</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="131" x="676.5" y="25.1328"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="117" x="683.5" y="45.1279">Instrumentation</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="131" x="676.5" y="1124.7422"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="117" x="683.5" y="1144.7373">Instrumentation</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="123" x="849.5" y="1124.7422"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="109" x="856.5" y="1144.7373">SecondActivity</text><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="102.6953"/><rect fill="#FFFFFF" height="370.6563" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="218.2266"/><rect fill="#FFFFFF" height="303.5234" style="stroke:#181818;stroke-width:1.0;" width="10" x="189" y="285.3594"/><rect fill="#FFFFFF" height="76.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="194" y="327.4922"/><rect fill="#FFFFFF" height="19" style="stroke:#181818;stroke-width:1.0;" width="10" x="199" y="384.7578"/><rect fill="#FFFFFF" height="59.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="744.4141"/><rect fill="#FFFFFF" height="168.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="184" y="948.2109"/><rect fill="#FFFFFF" height="34.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="189" y="1015.3438"/><rect fill="#FFFFFF" height="846.3828" style="stroke:#181818;stroke-width:1.0;" width="10" x="404" y="131.8281"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="409" y="184.0938"/><rect fill="#FFFFFF" height="352.1953" style="stroke:#181818;stroke-width:1.0;" width="10" x="409" y="626.0156"/><rect fill="#FFFFFF" height="106.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="414" y="668.1484"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="419" y="710.2813"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="414" y="914.0781"/><rect fill="#FFFFFF" height="14" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="460.1875"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="559.75"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="832.6797"/><rect fill="#FFFFFF" height="38.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="737" y="1078.6094"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="906" y="803.5469"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="906" y="1049.4766"/><ellipse cx="7.5" cy="101.9453" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="172,98.6953,182,102.6953,172,106.6953,176,102.6953" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="178" y1="102.6953" y2="102.6953"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="115" x="10" y="82.4966">&#9316; handleMessage</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="157" x="10" y="97.6294">EXECUTE_TRANSACTION</text><polygon fill="#181818" points="392,127.8281,402,131.8281,392,135.8281,396,131.8281" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="189" x2="398" y1="131.8281" y2="131.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="134" x="253" y="126.7622">execute(transaction)</text><line style="stroke:#181818;stroke-width:1.0;" x1="414" x2="461" y1="171.0938" y2="171.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="461" x2="461" y1="171.0938" y2="184.0938"/><line style="stroke:#181818;stroke-width:1.0;" x1="420" x2="461" y1="184.0938" y2="184.0938"/><polygon fill="#181818" points="430,180.0938,420,184.0938,430,188.0938,426,184.0938" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="123" x="426" y="150.895">LaunchActivityItem</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="56" x="426" y="166.0278">.execute</text><polygon fill="#181818" points="205,214.2266,195,218.2266,205,222.2266,201,218.2266" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="408" y1="218.2266" y2="218.2266"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="137" x="211" y="213.1606">handleLaunchActivity</text><line style="stroke:#181818;stroke-width:1.0;" x1="194" x2="241" y1="272.3594" y2="272.3594"/><line style="stroke:#181818;stroke-width:1.0;" x1="241" x2="241" y1="272.3594" y2="285.3594"/><line style="stroke:#181818;stroke-width:1.0;" x1="200" x2="241" y1="285.3594" y2="285.3594"/><polygon fill="#181818" points="210,281.3594,200,285.3594,210,289.3594,206,285.3594" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="146" x="206" y="267.2935">performLaunchActivity</text><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="246" y1="314.4922" y2="314.4922"/><line style="stroke:#181818;stroke-width:1.0;" x1="246" x2="246" y1="314.4922" y2="327.4922"/><line style="stroke:#181818;stroke-width:1.0;" x1="205" x2="246" y1="327.4922" y2="327.4922"/><polygon fill="#181818" points="215,323.4922,205,327.4922,215,331.4922,211,327.4922" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="191" x="211" y="309.4263">createBaseContextForActivity</text><line style="stroke:#181818;stroke-width:1.0;" x1="204" x2="251" y1="371.7578" y2="371.7578"/><line style="stroke:#181818;stroke-width:1.0;" x1="251" x2="251" y1="371.7578" y2="384.7578"/><line style="stroke:#181818;stroke-width:1.0;" x1="210" x2="251" y1="384.7578" y2="384.7578"/><polygon fill="#181818" points="220,380.7578,210,384.7578,220,388.7578,216,384.7578" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="99" x="216" y="351.5591">[ContextImpl]&#8594;</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="140" x="216" y="366.6919">createActivityContext</text><polygon fill="#181818" points="549.5,399.7578,559.5,403.7578,549.5,407.7578,553.5,403.7578" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="555.5" y1="403.7578" y2="403.7578"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="105" x="561.5" y="397.7578"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="91" x="568.5" y="417.7529">ContextImpl</text><polygon fill="#181818" points="725,456.1875,735,460.1875,725,464.1875,729,460.1875" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="731" y1="460.1875" y2="460.1875"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="75" x="645" y="455.1216">newActivity</text><polygon fill="#181818" points="837.5,470.1875,847.5,474.1875,837.5,478.1875,841.5,474.1875" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="742" x2="843.5" y1="474.1875" y2="474.1875"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="123" x="849.5" y="468.1875"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="109" x="856.5" y="488.1826">SecondActivity</text><polygon fill="#181818" points="899,526.6172,909,530.6172,899,534.6172,903,530.6172" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="905" y1="530.6172" y2="530.6172"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="57" x="837" y="525.5513">&#9312; attach</text><polygon fill="#181818" points="725,555.75,735,559.75,725,563.75,729,559.75" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="731" y1="559.75" y2="559.75"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="130" x="590" y="554.6841">callActivityOnCreate</text><polygon fill="#181818" points="899,584.8828,909,588.8828,899,592.8828,903,588.8828" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="742" x2="905" y1="588.8828" y2="588.8828"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="85" x="809" y="583.8169">&#9313; onCreate()</text><line style="stroke:#181818;stroke-width:1.0;" x1="414" x2="461" y1="613.0156" y2="613.0156"/><line style="stroke:#181818;stroke-width:1.0;" x1="461" x2="461" y1="613.0156" y2="626.0156"/><line style="stroke:#181818;stroke-width:1.0;" x1="420" x2="461" y1="626.0156" y2="626.0156"/><polygon fill="#181818" points="430,622.0156,420,626.0156,430,630.0156,426,626.0156" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="142" x="426" y="607.9497">executeLifecycleState</text><line style="stroke:#181818;stroke-width:1.0;" x1="419" x2="466" y1="655.1484" y2="655.1484"/><line style="stroke:#181818;stroke-width:1.0;" x1="466" x2="466" y1="655.1484" y2="668.1484"/><line style="stroke:#181818;stroke-width:1.0;" x1="425" x2="466" y1="668.1484" y2="668.1484"/><polygon fill="#181818" points="435,664.1484,425,668.1484,435,672.1484,431,668.1484" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="78" x="431" y="650.0825">cycleToPath</text><line style="stroke:#181818;stroke-width:1.0;" x1="424" x2="471" y1="697.2813" y2="697.2813"/><line style="stroke:#181818;stroke-width:1.0;" x1="471" x2="471" y1="697.2813" y2="710.2813"/><line style="stroke:#181818;stroke-width:1.0;" x1="430" x2="471" y1="710.2813" y2="710.2813"/><polygon fill="#181818" points="440,706.2813,430,710.2813,440,714.2813,436,710.2813" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="171" x="436" y="692.2153">performLifecycleSequence</text><polygon fill="#181818" points="205,740.4141,195,744.4141,205,748.4141,201,744.4141" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="418" y1="744.4141" y2="744.4141"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="122" x="211" y="739.3481">handleStartActivity</text><polygon fill="#181818" points="894,799.5469,904,803.5469,894,807.5469,898,803.5469" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="189" x2="900" y1="803.5469" y2="803.5469"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="83" x="806" y="798.481">performStart</text><polygon fill="#181818" points="758,828.6797,748,832.6797,758,836.6797,754,832.6797" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="752" x2="910" y1="832.6797" y2="832.6797"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="118" x="764" y="827.6138">callActivityOnStart</text><polygon fill="#181818" points="899,857.8125,909,861.8125,899,865.8125,903,861.8125" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="742" x2="905" y1="861.8125" y2="861.8125"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="73" x="821" y="856.7466">&#9314; onStart()</text><line style="stroke:#181818;stroke-width:1.0;" x1="419" x2="466" y1="901.0781" y2="901.0781"/><line style="stroke:#181818;stroke-width:1.0;" x1="466" x2="466" y1="901.0781" y2="914.0781"/><line style="stroke:#181818;stroke-width:1.0;" x1="425" x2="466" y1="914.0781" y2="914.0781"/><polygon fill="#181818" points="435,910.0781,425,914.0781,435,918.0781,431,914.0781" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="130" x="431" y="880.8794">ResumeActivityItem</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="56" x="431" y="896.0122">.execute</text><polygon fill="#181818" points="205,944.2109,195,948.2109,205,952.2109,201,948.2109" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="199" x2="413" y1="948.2109" y2="948.2109"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="144" x="211" y="943.145">handleResumeActivity</text><line style="stroke:#181818;stroke-width:1.0;" x1="194" x2="241" y1="1002.3438" y2="1002.3438"/><line style="stroke:#181818;stroke-width:1.0;" x1="241" x2="241" y1="1002.3438" y2="1015.3438"/><line style="stroke:#181818;stroke-width:1.0;" x1="200" x2="241" y1="1015.3438" y2="1015.3438"/><polygon fill="#181818" points="210,1011.3438,200,1015.3438,210,1019.3438,206,1015.3438" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="153" x="206" y="997.2778">performResumeActivity</text><polygon fill="#181818" points="894,1045.4766,904,1049.4766,894,1053.4766,898,1049.4766" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="194" x2="900" y1="1049.4766" y2="1049.4766"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="105" x="784" y="1044.4106">performResume</text><polygon fill="#181818" points="758,1074.6094,748,1078.6094,758,1082.6094,754,1078.6094" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="752" x2="910" y1="1078.6094" y2="1078.6094"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="140" x="764" y="1073.5435">callActivityOnResume</text><polygon fill="#181818" points="899,1103.7422,909,1107.7422,899,1111.7422,903,1107.7422" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="747" x2="905" y1="1107.7422" y2="1107.7422"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="95" x="799" y="1102.6763">&#9315; onResume()</text><!--SRC=[hLNBJi905DttAoPn0veQrovCAa92Wa2W9YPWp3YzqCRs3iuCY3_WNh_0rvVn9KvV2ALeYvHDoPnpxklSgRptS4853OY4XoaWWqkGaex1yhqn4W4p418kF05CUHoDEpudLhTB3XeduSyOSFECMFfivgadsnL07N9qT4eMBr_4fUZugTuGwzVrsfLTlxLxLhjlrUncfsrac5hB5XGbZOBLvy2cYWjYcg4aH7-XeduGLICNdgyIQhJe59cRHcqg28Pud0XlqygfBgviNSnm8EJEg8Ayy3cbvWXFG8ou23BAXQXCloaufn9g71NCLOEBSWg3XDWC9lxDulbrYB5c2asESyHMYEJmSBKJwzXVJZP5coYLc0Q0YeQDZ594U5pMb3tNb3umZawAoAIImUT4pD135xyHgXHbRi7y6FNz5Dd1MjI-0ecQPXZhdV24Kgdkr4FzbDo7nFejRmJiYVdGLtJx8cmJYPWsxrBbbgMcVb_6JowXqhke4nUgw2gMtjIDSQta7aKsieXDUyIaTOF4tAB- -D3-Y1ZQ7gKdtGEfG-pfvbiN-sUxztXlPl8gDyYOlECa4_BVemm7-Qa76HFq904Teh-gtm00]--></g></svg>

<h2 id="第四阶段：View添加到Window"><a href="#第四阶段：View添加到Window" class="headerlink" title="第四阶段：View添加到Window"></a>第四阶段：View添加到Window</h2><p>下面这个时序图是对上面时序图的进一步细化，① ② ③ ④与上面的序号一对一对应。</p>
<pre class="mermaid">

zenuml
group {
    &lt;&lt;App&gt;&gt; ActivityThread
    &lt;&lt;App&gt;&gt; SecondActivity
    PhoneWindow
    DecorView
    &lt;&lt;App&gt;&gt; WindowManagerGlobal
    ViewRootImpl
}


SecondActivity.&quot;① attach&quot; {
    attachBaseContext
    new PhoneWindow()
    PhoneWindow.setWindowManager
}
SecondActivity.&quot;② onCreate()&quot; {
    setContentView {
        PhoneWindow.installDecor {
            new DecorView()
            mContentParent &#x3D; generateLayout()
            &quot;mContentParent.addView&quot;
        }
    }
}
SecondActivity.&quot;③ onStart()&quot;
ActivityThread.handleResumeActivity {
    SecondActivity.&quot;④ onResume()&quot;
    DecorView.setVisibility(INVISIBLE)
    WindowManagerGlobal.addView(DecorView) {
        new ViewRootImpl()
        &quot;mViews.add(DecorView)&quot;
        &quot;mRoots.add(ViewRootImpl)&quot;
        ViewRootImpl.setView(DecorView)
    }
    SecondActivity.makeVisible {
        DecorView.setVisibility(VISIBLE) {
            ViewRootImpl.invalidateChild {
                invalidate {
                    scheduleTraversals
                }
            }
        }
    }
}
</pre>

<p>Activity.onCreate()中通过调用<code>setContentView</code>来触发DecorView的创建，DecorView就是rootView(<code>View#getRootView</code>)。通过<a target="_blank" rel="noopener external nofollow noreferrer" href="https://developer.android.google.cn/studio/profile/hierarchy-viewer">Hierarchy Viewer</a>看下DecorView结构：</p>
<p><img src="/images/Android/DecorView%E7%A4%BA%E4%BE%8B.png" alt="DecorView示例"></p>
<p>用户自定义的View会被添加到PhoneWindow.mContentParent中，而mContentParent是DecorView的一个子孙View。Activity.onResume()之后就会就会把DecorView添加到WindowManagerGlobal中，对生成对应的ViewRootImpl。ViewRootImpl就是DecorView的parent。</p>
<p>最后阶段就会执行UI的渲染，对应<code>ViewRootImpl.scheduleTraversals</code>。</p>
<p>下面是Activity、Task之间的类图关系：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="392px" preserveAspectRatio="none" style="width:1073px;height:392px;background:#FFFFFF;" version="1.1" viewBox="0 0 1073 392" width="1073px" zoomAndPan="magnify"><defs/><g><!--class WindowContainer--><g id="elem_WindowContainer"><rect codeLine="2" fill="#F1F1F1" height="48" id="WindowContainer" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="269" x="352" y="119"/><ellipse cx="367" cy="135" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M369.3438,130.6719 C368.4063,130.2344 367.8125,130.0938 366.9375,130.0938 C364.3125,130.0938 362.3125,132.1719 362.3125,134.8906 L362.3125,136.0156 C362.3125,138.5938 364.4219,140.4844 367.3125,140.4844 C368.5313,140.4844 369.6875,140.1875 370.4375,139.6406 C371.0156,139.2344 371.3438,138.7813 371.3438,138.3906 C371.3438,137.9375 370.9531,137.5469 370.4844,137.5469 C370.2656,137.5469 370.0625,137.625 369.875,137.8125 C369.4219,138.2969 369.4219,138.2969 369.2344,138.3906 C368.8125,138.6563 368.125,138.7813 367.3594,138.7813 C365.3125,138.7813 364.0156,137.6875 364.0156,135.9844 L364.0156,134.8906 C364.0156,133.1094 365.2656,131.7969 367,131.7969 C367.5781,131.7969 368.1875,131.9531 368.6563,132.2031 C369.1406,132.4844 369.3125,132.7031 369.4063,133.1094 C369.4688,133.5156 369.5,133.6406 369.6406,133.7656 C369.7813,133.9063 370.0156,134.0156 370.2344,134.0156 C370.5,134.0156 370.7656,133.875 370.9375,133.6563 C371.0469,133.5 371.0781,133.3125 371.0781,132.8906 L371.0781,131.4688 C371.0781,131.0313 371.0625,130.9063 370.9688,130.75 C370.8125,130.4844 370.5313,130.3438 370.2344,130.3438 C369.9375,130.3438 369.7344,130.4375 369.5156,130.75 L369.3438,130.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="381" y="139.8467">WindowContainer</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="108" x="516" y="116"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="106" x="517" y="128.1387">WindowContainer</text><line style="stroke:#181818;stroke-width:0.5;" x1="353" x2="620" y1="151" y2="151"/><line style="stroke:#181818;stroke-width:0.5;" x1="353" x2="620" y1="159" y2="159"/></g><!--class TaskFragment--><g id="elem_TaskFragment"><rect fill="#F1F1F1" height="48" id="TaskFragment" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="135" x="419" y="228"/><ellipse cx="434" cy="244" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M436.3438,239.6719 C435.4063,239.2344 434.8125,239.0938 433.9375,239.0938 C431.3125,239.0938 429.3125,241.1719 429.3125,243.8906 L429.3125,245.0156 C429.3125,247.5938 431.4219,249.4844 434.3125,249.4844 C435.5313,249.4844 436.6875,249.1875 437.4375,248.6406 C438.0156,248.2344 438.3438,247.7813 438.3438,247.3906 C438.3438,246.9375 437.9531,246.5469 437.4844,246.5469 C437.2656,246.5469 437.0625,246.625 436.875,246.8125 C436.4219,247.2969 436.4219,247.2969 436.2344,247.3906 C435.8125,247.6563 435.125,247.7813 434.3594,247.7813 C432.3125,247.7813 431.0156,246.6875 431.0156,244.9844 L431.0156,243.8906 C431.0156,242.1094 432.2656,240.7969 434,240.7969 C434.5781,240.7969 435.1875,240.9531 435.6563,241.2031 C436.1406,241.4844 436.3125,241.7031 436.4063,242.1094 C436.4688,242.5156 436.5,242.6406 436.6406,242.7656 C436.7813,242.9063 437.0156,243.0156 437.2344,243.0156 C437.5,243.0156 437.7656,242.875 437.9375,242.6563 C438.0469,242.5 438.0781,242.3125 438.0781,241.8906 L438.0781,240.4688 C438.0781,240.0313 438.0625,239.9063 437.9688,239.75 C437.8125,239.4844 437.5313,239.3438 437.2344,239.3438 C436.9375,239.3438 436.7344,239.4375 436.5156,239.75 L436.3438,239.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="103" x="448" y="248.8467">TaskFragment</text><line style="stroke:#181818;stroke-width:0.5;" x1="420" x2="553" y1="260" y2="260"/><line style="stroke:#181818;stroke-width:0.5;" x1="420" x2="553" y1="268" y2="268"/></g><!--class Task--><g id="elem_Task"><rect fill="#F1F1F1" height="48" id="Task" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="65" x="454" y="337"/><ellipse cx="469" cy="353" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M471.3438,348.6719 C470.4063,348.2344 469.8125,348.0938 468.9375,348.0938 C466.3125,348.0938 464.3125,350.1719 464.3125,352.8906 L464.3125,354.0156 C464.3125,356.5938 466.4219,358.4844 469.3125,358.4844 C470.5313,358.4844 471.6875,358.1875 472.4375,357.6406 C473.0156,357.2344 473.3438,356.7813 473.3438,356.3906 C473.3438,355.9375 472.9531,355.5469 472.4844,355.5469 C472.2656,355.5469 472.0625,355.625 471.875,355.8125 C471.4219,356.2969 471.4219,356.2969 471.2344,356.3906 C470.8125,356.6563 470.125,356.7813 469.3594,356.7813 C467.3125,356.7813 466.0156,355.6875 466.0156,353.9844 L466.0156,352.8906 C466.0156,351.1094 467.2656,349.7969 469,349.7969 C469.5781,349.7969 470.1875,349.9531 470.6563,350.2031 C471.1406,350.4844 471.3125,350.7031 471.4063,351.1094 C471.4688,351.5156 471.5,351.6406 471.6406,351.7656 C471.7813,351.9063 472.0156,352.0156 472.2344,352.0156 C472.5,352.0156 472.7656,351.875 472.9375,351.6563 C473.0469,351.5 473.0781,351.3125 473.0781,350.8906 L473.0781,349.4688 C473.0781,349.0313 473.0625,348.9063 472.9688,348.75 C472.8125,348.4844 472.5313,348.3438 472.2344,348.3438 C471.9375,348.3438 471.7344,348.4375 471.5156,348.75 L471.3438,348.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="33" x="483" y="357.8467">Task</text><line style="stroke:#181818;stroke-width:0.5;" x1="455" x2="518" y1="369" y2="369"/><line style="stroke:#181818;stroke-width:0.5;" x1="455" x2="518" y1="377" y2="377"/></g><!--class RootDisplayArea--><g id="elem_RootDisplayArea"><rect fill="#F1F1F1" height="48" id="RootDisplayArea" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="152" x="643.5" y="228"/><ellipse cx="658.5" cy="244" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M660.8438,239.6719 C659.9063,239.2344 659.3125,239.0938 658.4375,239.0938 C655.8125,239.0938 653.8125,241.1719 653.8125,243.8906 L653.8125,245.0156 C653.8125,247.5938 655.9219,249.4844 658.8125,249.4844 C660.0313,249.4844 661.1875,249.1875 661.9375,248.6406 C662.5156,248.2344 662.8438,247.7813 662.8438,247.3906 C662.8438,246.9375 662.4531,246.5469 661.9844,246.5469 C661.7656,246.5469 661.5625,246.625 661.375,246.8125 C660.9219,247.2969 660.9219,247.2969 660.7344,247.3906 C660.3125,247.6563 659.625,247.7813 658.8594,247.7813 C656.8125,247.7813 655.5156,246.6875 655.5156,244.9844 L655.5156,243.8906 C655.5156,242.1094 656.7656,240.7969 658.5,240.7969 C659.0781,240.7969 659.6875,240.9531 660.1563,241.2031 C660.6406,241.4844 660.8125,241.7031 660.9063,242.1094 C660.9688,242.5156 661,242.6406 661.1406,242.7656 C661.2813,242.9063 661.5156,243.0156 661.7344,243.0156 C662,243.0156 662.2656,242.875 662.4375,242.6563 C662.5469,242.5 662.5781,242.3125 662.5781,241.8906 L662.5781,240.4688 C662.5781,240.0313 662.5625,239.9063 662.4688,239.75 C662.3125,239.4844 662.0313,239.3438 661.7344,239.3438 C661.4375,239.3438 661.2344,239.4375 661.0156,239.75 L660.8438,239.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="120" x="672.5" y="248.8467">RootDisplayArea</text><line style="stroke:#181818;stroke-width:0.5;" x1="644.5" x2="794.5" y1="260" y2="260"/><line style="stroke:#181818;stroke-width:0.5;" x1="644.5" x2="794.5" y1="268" y2="268"/></g><!--class DisplayContent--><g id="elem_DisplayContent"><rect fill="#F1F1F1" height="48" id="DisplayContent" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="144" x="753.5" y="337"/><ellipse cx="768.5" cy="353" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M770.8438,348.6719 C769.9063,348.2344 769.3125,348.0938 768.4375,348.0938 C765.8125,348.0938 763.8125,350.1719 763.8125,352.8906 L763.8125,354.0156 C763.8125,356.5938 765.9219,358.4844 768.8125,358.4844 C770.0313,358.4844 771.1875,358.1875 771.9375,357.6406 C772.5156,357.2344 772.8438,356.7813 772.8438,356.3906 C772.8438,355.9375 772.4531,355.5469 771.9844,355.5469 C771.7656,355.5469 771.5625,355.625 771.375,355.8125 C770.9219,356.2969 770.9219,356.2969 770.7344,356.3906 C770.3125,356.6563 769.625,356.7813 768.8594,356.7813 C766.8125,356.7813 765.5156,355.6875 765.5156,353.9844 L765.5156,352.8906 C765.5156,351.1094 766.7656,349.7969 768.5,349.7969 C769.0781,349.7969 769.6875,349.9531 770.1563,350.2031 C770.6406,350.4844 770.8125,350.7031 770.9063,351.1094 C770.9688,351.5156 771,351.6406 771.1406,351.7656 C771.2813,351.9063 771.5156,352.0156 771.7344,352.0156 C772,352.0156 772.2656,351.875 772.4375,351.6563 C772.5469,351.5 772.5781,351.3125 772.5781,350.8906 L772.5781,349.4688 C772.5781,349.0313 772.5625,348.9063 772.4688,348.75 C772.3125,348.4844 772.0313,348.3438 771.7344,348.3438 C771.4375,348.3438 771.2344,348.4375 771.0156,348.75 L770.8438,348.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="112" x="782.5" y="357.8467">DisplayContent</text><line style="stroke:#181818;stroke-width:0.5;" x1="754.5" x2="896.5" y1="369" y2="369"/><line style="stroke:#181818;stroke-width:0.5;" x1="754.5" x2="896.5" y1="377" y2="377"/></g><!--class WindowContainer1--><g id="elem_WindowContainer1"><rect codeLine="8" fill="#F1F1F1" height="48" id="WindowContainer1" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="233" x="507" y="10"/><ellipse cx="522" cy="26" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M524.3438,21.6719 C523.4063,21.2344 522.8125,21.0938 521.9375,21.0938 C519.3125,21.0938 517.3125,23.1719 517.3125,25.8906 L517.3125,27.0156 C517.3125,29.5938 519.4219,31.4844 522.3125,31.4844 C523.5313,31.4844 524.6875,31.1875 525.4375,30.6406 C526.0156,30.2344 526.3438,29.7813 526.3438,29.3906 C526.3438,28.9375 525.9531,28.5469 525.4844,28.5469 C525.2656,28.5469 525.0625,28.625 524.875,28.8125 C524.4219,29.2969 524.4219,29.2969 524.2344,29.3906 C523.8125,29.6563 523.125,29.7813 522.3594,29.7813 C520.3125,29.7813 519.0156,28.6875 519.0156,26.9844 L519.0156,25.8906 C519.0156,24.1094 520.2656,22.7969 522,22.7969 C522.5781,22.7969 523.1875,22.9531 523.6563,23.2031 C524.1406,23.4844 524.3125,23.7031 524.4063,24.1094 C524.4688,24.5156 524.5,24.6406 524.6406,24.7656 C524.7813,24.9063 525.0156,25.0156 525.2344,25.0156 C525.5,25.0156 525.7656,24.875 525.9375,24.6563 C526.0469,24.5 526.0781,24.3125 526.0781,23.8906 L526.0781,22.4688 C526.0781,22.0313 526.0625,21.9063 525.9688,21.75 C525.8125,21.4844 525.5313,21.3438 525.2344,21.3438 C524.9375,21.3438 524.7344,21.4375 524.5156,21.75 L524.3438,21.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="536" y="30.8467">WindowContainer</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="72" x="671" y="7"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="70" x="672" y="19.1387">DisplayArea</text><line style="stroke:#181818;stroke-width:0.5;" x1="508" x2="739" y1="42" y2="42"/><line style="stroke:#181818;stroke-width:0.5;" x1="508" x2="739" y1="50" y2="50"/></g><!--class DisplayArea--><g id="elem_DisplayArea"><rect fill="#F1F1F1" height="48" id="DisplayArea" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="117" x="656" y="119"/><ellipse cx="671" cy="135" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M673.3438,130.6719 C672.4063,130.2344 671.8125,130.0938 670.9375,130.0938 C668.3125,130.0938 666.3125,132.1719 666.3125,134.8906 L666.3125,136.0156 C666.3125,138.5938 668.4219,140.4844 671.3125,140.4844 C672.5313,140.4844 673.6875,140.1875 674.4375,139.6406 C675.0156,139.2344 675.3438,138.7813 675.3438,138.3906 C675.3438,137.9375 674.9531,137.5469 674.4844,137.5469 C674.2656,137.5469 674.0625,137.625 673.875,137.8125 C673.4219,138.2969 673.4219,138.2969 673.2344,138.3906 C672.8125,138.6563 672.125,138.7813 671.3594,138.7813 C669.3125,138.7813 668.0156,137.6875 668.0156,135.9844 L668.0156,134.8906 C668.0156,133.1094 669.2656,131.7969 671,131.7969 C671.5781,131.7969 672.1875,131.9531 672.6563,132.2031 C673.1406,132.4844 673.3125,132.7031 673.4063,133.1094 C673.4688,133.5156 673.5,133.6406 673.6406,133.7656 C673.7813,133.9063 674.0156,134.0156 674.2344,134.0156 C674.5,134.0156 674.7656,133.875 674.9375,133.6563 C675.0469,133.5 675.0781,133.3125 675.0781,132.8906 L675.0781,131.4688 C675.0781,131.0313 675.0625,130.9063 674.9688,130.75 C674.8125,130.4844 674.5313,130.3438 674.2344,130.3438 C673.9375,130.3438 673.7344,130.4375 673.5156,130.75 L673.3438,130.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="85" x="685" y="139.8467">DisplayArea</text><line style="stroke:#181818;stroke-width:0.5;" x1="657" x2="772" y1="151" y2="151"/><line style="stroke:#181818;stroke-width:0.5;" x1="657" x2="772" y1="159" y2="159"/></g><!--class WindowContainer2--><g id="elem_WindowContainer2"><rect codeLine="13" fill="#F1F1F1" height="48" id="WindowContainer2" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="254" x="808.5" y="119"/><ellipse cx="823.5" cy="135" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M825.8438,130.6719 C824.9063,130.2344 824.3125,130.0938 823.4375,130.0938 C820.8125,130.0938 818.8125,132.1719 818.8125,134.8906 L818.8125,136.0156 C818.8125,138.5938 820.9219,140.4844 823.8125,140.4844 C825.0313,140.4844 826.1875,140.1875 826.9375,139.6406 C827.5156,139.2344 827.8438,138.7813 827.8438,138.3906 C827.8438,137.9375 827.4531,137.5469 826.9844,137.5469 C826.7656,137.5469 826.5625,137.625 826.375,137.8125 C825.9219,138.2969 825.9219,138.2969 825.7344,138.3906 C825.3125,138.6563 824.625,138.7813 823.8594,138.7813 C821.8125,138.7813 820.5156,137.6875 820.5156,135.9844 L820.5156,134.8906 C820.5156,133.1094 821.7656,131.7969 823.5,131.7969 C824.0781,131.7969 824.6875,131.9531 825.1563,132.2031 C825.6406,132.4844 825.8125,132.7031 825.9063,133.1094 C825.9688,133.5156 826,133.6406 826.1406,133.7656 C826.2813,133.9063 826.5156,134.0156 826.7344,134.0156 C827,134.0156 827.2656,133.875 827.4375,133.6563 C827.5469,133.5 827.5781,133.3125 827.5781,132.8906 L827.5781,131.4688 C827.5781,131.0313 827.5625,130.9063 827.4688,130.75 C827.3125,130.4844 827.0313,130.3438 826.7344,130.3438 C826.4375,130.3438 826.2344,130.4375 826.0156,130.75 L825.8438,130.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="837.5" y="139.8467">WindowContainer</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="93" x="972.5" y="116"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="91" x="973.5" y="128.1387">DisplayContent</text><line style="stroke:#181818;stroke-width:0.5;" x1="809.5" x2="1061.5" y1="151" y2="151"/><line style="stroke:#181818;stroke-width:0.5;" x1="809.5" x2="1061.5" y1="159" y2="159"/></g><!--class RootWindowContainer--><g id="elem_RootWindowContainer"><rect fill="#F1F1F1" height="48" id="RootWindowContainer" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="194" x="836.5" y="228"/><ellipse cx="851.5" cy="244" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M853.8438,239.6719 C852.9063,239.2344 852.3125,239.0938 851.4375,239.0938 C848.8125,239.0938 846.8125,241.1719 846.8125,243.8906 L846.8125,245.0156 C846.8125,247.5938 848.9219,249.4844 851.8125,249.4844 C853.0313,249.4844 854.1875,249.1875 854.9375,248.6406 C855.5156,248.2344 855.8438,247.7813 855.8438,247.3906 C855.8438,246.9375 855.4531,246.5469 854.9844,246.5469 C854.7656,246.5469 854.5625,246.625 854.375,246.8125 C853.9219,247.2969 853.9219,247.2969 853.7344,247.3906 C853.3125,247.6563 852.625,247.7813 851.8594,247.7813 C849.8125,247.7813 848.5156,246.6875 848.5156,244.9844 L848.5156,243.8906 C848.5156,242.1094 849.7656,240.7969 851.5,240.7969 C852.0781,240.7969 852.6875,240.9531 853.1563,241.2031 C853.6406,241.4844 853.8125,241.7031 853.9063,242.1094 C853.9688,242.5156 854,242.6406 854.1406,242.7656 C854.2813,242.9063 854.5156,243.0156 854.7344,243.0156 C855,243.0156 855.2656,242.875 855.4375,242.6563 C855.5469,242.5 855.5781,242.3125 855.5781,241.8906 L855.5781,240.4688 C855.5781,240.0313 855.5625,239.9063 855.4688,239.75 C855.3125,239.4844 855.0313,239.3438 854.7344,239.3438 C854.4375,239.3438 854.2344,239.4375 854.0156,239.75 L853.8438,239.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="162" x="865.5" y="248.8467">RootWindowContainer</text><line style="stroke:#181818;stroke-width:0.5;" x1="837.5" x2="1029.5" y1="260" y2="260"/><line style="stroke:#181818;stroke-width:0.5;" x1="837.5" x2="1029.5" y1="268" y2="268"/></g><!--class WindowContainer3--><g id="elem_WindowContainer3"><rect codeLine="17" fill="#F1F1F1" height="48" id="WindowContainer3" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="243" x="7" y="119"/><ellipse cx="22" cy="135" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,130.6719 C23.4063,130.2344 22.8125,130.0938 21.9375,130.0938 C19.3125,130.0938 17.3125,132.1719 17.3125,134.8906 L17.3125,136.0156 C17.3125,138.5938 19.4219,140.4844 22.3125,140.4844 C23.5313,140.4844 24.6875,140.1875 25.4375,139.6406 C26.0156,139.2344 26.3438,138.7813 26.3438,138.3906 C26.3438,137.9375 25.9531,137.5469 25.4844,137.5469 C25.2656,137.5469 25.0625,137.625 24.875,137.8125 C24.4219,138.2969 24.4219,138.2969 24.2344,138.3906 C23.8125,138.6563 23.125,138.7813 22.3594,138.7813 C20.3125,138.7813 19.0156,137.6875 19.0156,135.9844 L19.0156,134.8906 C19.0156,133.1094 20.2656,131.7969 22,131.7969 C22.5781,131.7969 23.1875,131.9531 23.6563,132.2031 C24.1406,132.4844 24.3125,132.7031 24.4063,133.1094 C24.4688,133.5156 24.5,133.6406 24.6406,133.7656 C24.7813,133.9063 25.0156,134.0156 25.2344,134.0156 C25.5,134.0156 25.7656,133.875 25.9375,133.6563 C26.0469,133.5 26.0781,133.3125 26.0781,132.8906 L26.0781,131.4688 C26.0781,131.0313 26.0625,130.9063 25.9688,130.75 C25.8125,130.4844 25.5313,130.3438 25.2344,130.3438 C24.9375,130.3438 24.7344,130.4375 24.5156,130.75 L24.3438,130.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="127" x="36" y="139.8467">WindowContainer</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="82" x="171" y="116"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="80" x="172" y="128.1387">WindowState</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="249" y1="151" y2="151"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="249" y1="159" y2="159"/></g><!--class WindowToken--><g id="elem_WindowToken"><rect fill="#F1F1F1" height="48" id="WindowToken" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="133" x="62" y="228"/><ellipse cx="77" cy="244" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M79.3438,239.6719 C78.4063,239.2344 77.8125,239.0938 76.9375,239.0938 C74.3125,239.0938 72.3125,241.1719 72.3125,243.8906 L72.3125,245.0156 C72.3125,247.5938 74.4219,249.4844 77.3125,249.4844 C78.5313,249.4844 79.6875,249.1875 80.4375,248.6406 C81.0156,248.2344 81.3438,247.7813 81.3438,247.3906 C81.3438,246.9375 80.9531,246.5469 80.4844,246.5469 C80.2656,246.5469 80.0625,246.625 79.875,246.8125 C79.4219,247.2969 79.4219,247.2969 79.2344,247.3906 C78.8125,247.6563 78.125,247.7813 77.3594,247.7813 C75.3125,247.7813 74.0156,246.6875 74.0156,244.9844 L74.0156,243.8906 C74.0156,242.1094 75.2656,240.7969 77,240.7969 C77.5781,240.7969 78.1875,240.9531 78.6563,241.2031 C79.1406,241.4844 79.3125,241.7031 79.4063,242.1094 C79.4688,242.5156 79.5,242.6406 79.6406,242.7656 C79.7813,242.9063 80.0156,243.0156 80.2344,243.0156 C80.5,243.0156 80.7656,242.875 80.9375,242.6563 C81.0469,242.5 81.0781,242.3125 81.0781,241.8906 L81.0781,240.4688 C81.0781,240.0313 81.0625,239.9063 80.9688,239.75 C80.8125,239.4844 80.5313,239.3438 80.2344,239.3438 C79.9375,239.3438 79.7344,239.4375 79.5156,239.75 L79.3438,239.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="101" x="91" y="248.8467">WindowToken</text><line style="stroke:#181818;stroke-width:0.5;" x1="63" x2="194" y1="260" y2="260"/><line style="stroke:#181818;stroke-width:0.5;" x1="63" x2="194" y1="268" y2="268"/></g><!--class ActivityRecord--><g id="elem_ActivityRecord"><rect fill="#F1F1F1" height="48" id="ActivityRecord" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="139" x="59" y="337"/><ellipse cx="74" cy="353" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M76.3438,348.6719 C75.4063,348.2344 74.8125,348.0938 73.9375,348.0938 C71.3125,348.0938 69.3125,350.1719 69.3125,352.8906 L69.3125,354.0156 C69.3125,356.5938 71.4219,358.4844 74.3125,358.4844 C75.5313,358.4844 76.6875,358.1875 77.4375,357.6406 C78.0156,357.2344 78.3438,356.7813 78.3438,356.3906 C78.3438,355.9375 77.9531,355.5469 77.4844,355.5469 C77.2656,355.5469 77.0625,355.625 76.875,355.8125 C76.4219,356.2969 76.4219,356.2969 76.2344,356.3906 C75.8125,356.6563 75.125,356.7813 74.3594,356.7813 C72.3125,356.7813 71.0156,355.6875 71.0156,353.9844 L71.0156,352.8906 C71.0156,351.1094 72.2656,349.7969 74,349.7969 C74.5781,349.7969 75.1875,349.9531 75.6563,350.2031 C76.1406,350.4844 76.3125,350.7031 76.4063,351.1094 C76.4688,351.5156 76.5,351.6406 76.6406,351.7656 C76.7813,351.9063 77.0156,352.0156 77.2344,352.0156 C77.5,352.0156 77.7656,351.875 77.9375,351.6563 C78.0469,351.5 78.0781,351.3125 78.0781,350.8906 L78.0781,349.4688 C78.0781,349.0313 78.0625,348.9063 77.9688,348.75 C77.8125,348.4844 77.5313,348.3438 77.2344,348.3438 C76.9375,348.3438 76.7344,348.4375 76.5156,348.75 L76.3438,348.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="107" x="88" y="357.8467">ActivityRecord</text><line style="stroke:#181818;stroke-width:0.5;" x1="60" x2="197" y1="369" y2="369"/><line style="stroke:#181818;stroke-width:0.5;" x1="60" x2="197" y1="377" y2="377"/></g><!--reverse link WindowContainer to TaskFragment--><g id="link_WindowContainer_TaskFragment"><path codeLine="4" d="M486.5,185.217 C486.5,203.165 486.5,209.892 486.5,227.828 " fill="none" id="WindowContainer-backto-TaskFragment" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="486.5,167.217,480.5,185.217,492.5,185.217,486.5,167.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link TaskFragment to Task--><g id="link_TaskFragment_Task"><path codeLine="5" d="M486.5,294.217 C486.5,312.1649 486.5,318.8918 486.5,336.8279 " fill="none" id="TaskFragment-backto-Task" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="486.5,276.217,480.5,294.217,492.5,294.217,486.5,276.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link RootDisplayArea to DisplayContent--><g id="link_RootDisplayArea_DisplayContent"><path codeLine="7" d="M755.168,289.0046 C772.948,306.9525 784.776,318.8918 802.544,336.8279 " fill="none" id="RootDisplayArea-backto-DisplayContent" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="742.5,276.217,750.9054,293.2273,759.4305,284.7819,742.5,276.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link WindowContainer1 to DisplayArea--><g id="link_WindowContainer1_DisplayArea"><path codeLine="9" d="M654.9069,71.9292 C670.1699,89.8772 679.539,100.892 694.793,118.828 " fill="none" id="WindowContainer1-backto-DisplayArea" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="643.246,58.217,650.3361,75.8161,659.4776,68.0422,643.246,58.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DisplayArea to RootDisplayArea--><g id="link_DisplayArea_RootDisplayArea"><path codeLine="10" d="M716.4255,185.1974 C717.2645,203.1454 717.579,209.892 718.417,227.828 " fill="none" id="DisplayArea-backto-RootDisplayArea" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="715.585,167.217,710.4321,185.4775,722.419,184.9172,715.585,167.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link WindowContainer1 to WindowContainer--><g id="link_WindowContainer1_WindowContainer"><path codeLine="11" d="M584.3158,65.6036 C561.3368,83.5516 539.134,100.892 516.169,118.828 " fill="none" id="WindowContainer1-backto-WindowContainer" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="593.773,58.217,586.5822,58.7579,584.3158,65.6036,591.5066,65.0627,593.773,58.217" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="577.552" y="78.0311">1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="514.7467" y="107.796">n</text></g><!--reverse link WindowContainer2 to RootWindowContainer--><g id="link_WindowContainer2_RootWindowContainer"><path codeLine="14" d="M934.7301,185.2139 C934.3951,203.1619 934.268,209.892 933.933,227.828 " fill="none" id="WindowContainer2-backto-RootWindowContainer" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="935.066,167.217,928.7311,185.1019,940.729,185.3258,935.066,167.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link RootWindowContainer to DisplayContent--><g id="link_RootWindowContainer_DisplayContent"><path codeLine="15" d="M901.5413,284.6626 C883.4253,302.6105 866.992,318.8918 848.889,336.8279 " fill="none" id="RootWindowContainer-backto-DisplayContent" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="910.066,276.217,902.9884,277.5982,901.5413,284.6626,908.6188,283.2814,910.066,276.217" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="895.379" y="296.0311">1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="845.8574" y="325.7958">n</text></g><!--reverse link WindowContainer3 to WindowToken--><g id="link_WindowContainer3_WindowToken"><path codeLine="18" d="M128.5,185.217 C128.5,203.165 128.5,209.892 128.5,227.828 " fill="none" id="WindowContainer3-backto-WindowToken" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="128.5,167.217,122.5,185.217,134.5,185.217,128.5,167.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link WindowToken to ActivityRecord--><g id="link_WindowToken_ActivityRecord"><path codeLine="19" d="M128.5,294.217 C128.5,312.1649 128.5,318.8918 128.5,336.8279 " fill="none" id="WindowToken-backto-ActivityRecord" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="128.5,276.217,122.5,294.217,134.5,294.217,128.5,276.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--link WindowContainer3 to WindowContainer--><g id="link_WindowContainer3_WindowContainer"><path codeLine="21" d="M250.202,143 C282.939,143 306.534,143 339.927,143 " fill="none" id="WindowContainer3-to-WindowContainer" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="351.927,143,345.927,139,339.927,143,345.927,147,351.927,143" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65" x="268.5" y="136.0669">mChildren</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="257.862" y="139.6139">n</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="335.9157" y="139.6371">1</text></g><!--SRC=[XPB12i8m38RlVOhGYo3iC7SJ4KJn0LJm7BUgnQsLDYg23-z6HMTQyRO_pPzyVzW0SEV9OKamjsQl3nU7fArf1Q4soasssbJszjPJKTReFR1ot3RuCH0cZopZTi5qQDgWFoqT7XfbIFJ5vxbTmwt331RQdskyTxNEkhAMNgMPKnZSh2UaaZnMppQLW57kd9FdNzCxduXMCvvuXCnb6oC3QMHqgJ-ahpn9s17VDFhmy3M9sXSMEzylgg3NXAIII0L7Alh_nyQUb16zx_0uAqbVDTrNghIk4YBDMQiz9KzOm1YQ-L7NbLFc2G00]--></g></svg>

<h2 id="启动新APP进程"><a href="#启动新APP进程" class="headerlink" title="启动新APP进程"></a>启动新APP进程</h2><p>如果需要启动的activity不在同一个app中，就需要启动新的进程。</p>
<pre class="mermaid">

zenuml
ActivityTaskManagerService.startProcessAsync {
    H.sendMessage {
        ActivityManagerService.startProcess {
            startProcessLocked {
                ProcessList.startProcessLocked {
                    newProcessRecordLocked {
                        new ProcessRecord()
                    }
                    &#x2F;&#x2F;with ProcessRecord
                    startProcessLocked {
                        ProcessList.&quot;配置runtimeFlags&quot;
                        &#x2F;&#x2F;异步启动线程
                        ProcessList -&gt; ActivityManagerService : mProcStartHandler.post
                    }
                }
            }
        }
    }
}
</pre>

<pre class="mermaid">

zenuml
ActivityManagerService.&quot;mProcStartHandler.dispatchMessage&quot; {
    ProcessList.handleProcessStart {
        startProcess {
            ProcessStartResult &#x3D; Process.start {
                ProcessStartResult &#x3D; ZygoteProcess.start {
                    startViaZygote {
                        ZygoteProcess.&quot;组装参数列表args&quot;
                        zygoteSendArgsAndGetResult {
                            &#x2F;&#x2F;通过LocalSocket向zygote发送进程启动参数
                            &#x2F;&#x2F;并阻塞读取进程pid
                            attemptZygoteSendArgsAndGetResult
                        }
                    }
                }
            }
        }
        handleProcessStartedLocked {
            ActivityManagerService.addPidLocked {
                ActivityTaskManagerService.&quot;onProcessMapped(pid, WindowProcessController)&quot; {
                    ActivityTaskManagerService.&quot;mProcessMap.put(pid, proc)&quot;
                }
            }
        }
    }
}
</pre>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//android-13.0.0_r41\frameworks\base\core\java\android\os\ZygoteProcess.java</span></span><br><span class="line">    <span class="keyword">private</span> Process.ProcessStartResult <span class="title function_">attemptZygoteSendArgsAndGetResult</span><span class="params">(</span></span><br><span class="line"><span class="params">            ZygoteState zygoteState, String msgStr)</span> <span class="keyword">throws</span> ZygoteStartFailedEx &#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="keyword">final</span> <span class="type">BufferedWriter</span> <span class="variable">zygoteWriter</span> <span class="operator">=</span> zygoteState.mZygoteOutputWriter;</span><br><span class="line">            <span class="keyword">final</span> <span class="type">DataInputStream</span> <span class="variable">zygoteInputStream</span> <span class="operator">=</span> zygoteState.mZygoteInputStream;</span><br><span class="line"></span><br><span class="line">            <span class="comment">//通过LocalSocket将进程启动参数传输给zygote进程</span></span><br><span class="line">            zygoteWriter.write(msgStr);</span><br><span class="line">            zygoteWriter.flush();</span><br><span class="line"></span><br><span class="line">            Process.<span class="type">ProcessStartResult</span> <span class="variable">result</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Process</span>.ProcessStartResult();</span><br><span class="line">            <span class="comment">//读取新进程的pid</span></span><br><span class="line">            result.pid = zygoteInputStream.readInt();</span><br><span class="line">            result.usingWrapper = zygoteInputStream.readBoolean();</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (result.pid &lt; <span class="number">0</span>) &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">ZygoteStartFailedEx</span>(<span class="string">&quot;fork() failed&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> result;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException ex) &#123;</span><br><span class="line">            zygoteState.close();</span><br><span class="line">            Log.e(LOG_TAG, <span class="string">&quot;IO Exception while communicating with Zygote - &quot;</span></span><br><span class="line">                    + ex.toString());</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">ZygoteStartFailedEx</span>(ex);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>新的app进程启动运行的入口是<code>ActivityThread.main</code>函数：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">    ......</span><br><span class="line">    <span class="comment">//初始化主线程Looper</span></span><br><span class="line">    Looper.prepareMainLooper();</span><br><span class="line"></span><br><span class="line">    ......</span><br><span class="line">    <span class="comment">//创建ActivityThread</span></span><br><span class="line">    <span class="type">ActivityThread</span> <span class="variable">thread</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ActivityThread</span>();</span><br><span class="line">    thread.attach(<span class="literal">false</span>, startSeq);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (sMainThreadHandler == <span class="literal">null</span>) &#123;</span><br><span class="line">        sMainThreadHandler = thread.getHandler();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    ......</span><br><span class="line">    <span class="comment">//启动主线程消息循环</span></span><br><span class="line">    Looper.loop();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">RuntimeException</span>(<span class="string">&quot;Main thread loop unexpectedly exited&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<pre class="mermaid">

zenuml
group App {
    ApplicationThread
    Application
    ActivityThread
    mH
}
group AMS {
    ActivityManagerService
}
ActivityThread.attach {
    ActivityManagerService.attachApplication {
        Binder.getCallingPid
        attachApplicationLocked {
            &quot;根据pid获取ProcessRecord&quot;
            ApplicationThread.bindApplication {
                mH.sendMessage(BIND_APPLICATION)
            }
        }
    }
}
ActivityThread.handleMessage(BIND_APPLICATION) {
    handleBindApplication {
        new Application()
        Application.attachBaseContext()
        Application.onCreate()
    }
}
</pre>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Android/" rel="tag"># Android</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/posts/c09f2087.html" rel="prev" title="Android UI 绘制流程">
                  <i class="fa fa-angle-left"></i> Android UI 绘制流程
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/posts/936e646.html" rel="next" title="Android Jni开发指南">
                  Android Jni开发指南 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Jason</span>
  </div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener external nofollow noreferrer" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener external nofollow noreferrer" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.umd.js" integrity="sha256-oyhjPiYRWGXaAt+ny/mTMWOnN1GBoZDUQnzzgC7FRI4=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>


  <script class="next-config" data-name="mermaid" type="application/json">{"enable":true,"theme":{"light":"default","dark":"dark"},"js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.min.js","integrity":"sha256-K7oJiQlDulzl24ZUFOywuYme1JqBBvQzK6m8qHjt9Gk="}}</script>
  <script type="module" src="/js/zenuml-definition-074a43fa.js"></script>
  <script type="module" src="/js/mermaid-zenuml.esm.min.mjs"></script>
  <script src="/js/third-party/tags/mermaid.js"></script>


  <script src="/js/third-party/fancybox.js"></script>



  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>



</body>
</html>
